#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/hrtimer.h>
#include <linux/ktime.h>

struct hrtimer timer;

enum hrtimer_restart timer_handler(struct hrtimer *timer)
{
    printk("hrtimer handler\n");
    return HRTIMER_NORESTART;
}

static int __init test_init(void){
    char *buf;
    ktime_t tim;
    printk("hello world\n");

    hrtimer_init(&timer,CLOCK_MONOTONIC,HRTIMER_MODE_REL);
    timer.function = timer_handler;
    tim = ktime_set(1,0);
    hrtimer_start(&timer, tim, HRTIMER_MODE_REL);
    
    buf = kmalloc(10,GFP_KERNEL);
    if (unlikely(buf == NULL)) {
		printk(KERN_ERR "could not allocate integrity buffer\n");
		return -1;
	}
    strcpy(buf, "ttt!");
    printk("%s\n",buf);
    kfree(buf);
    return 0;
}

static void __exit test_exit(void){
    printk("bye\n");
    hrtimer_cancel(&timer);
}

module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");

